﻿using WMLogistics.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DapperExtensions;
using Dapper;
using DapperExtensions.Mapper;
using DapperExtensions.Sql;

namespace WMLogistics_Dao
{
    public class AndroidTokenDao
    {
        /// <summary>
        /// 通过物流ID获取Token
        /// </summary>
        /// <param name="wuliu_id"></param>
        /// <returns></returns>
        public List<wuliu_account_android_token> GetAndroidToken(int wuliu_id)
        {
            string sql = @"SELECT a.* from wuliu_account_android_token as a
                            LEFT JOIN wuliu_account_role as b on a.account_id=b.account_id
                            LEFT JOIN wuliu_account_wlcompany as c on a.account_id=c.account_id
                            WHERE b.role_id in (10,11) and c.wuliu_id=@wuliu_id";
            using (var conn = ConnectionHelper.OpenConnection())
            {
                return conn.Query<wuliu_account_android_token>(sql, new { wuliu_id }).ToList();
            }
        }
        public List<wuliu_account_ios_token> GetIOSToken(int wuliu_id)
        {
            string sql = @"SELECT a.* from wuliu_account_ios_token as a
                            LEFT JOIN wuliu_account_role as b on a.account_id=b.account_id
                            LEFT JOIN wuliu_account_wlcompany as c on a.account_id=c.account_id
                            WHERE b.role_id in (10,11) and c.wuliu_id=@wuliu_id";
            using (var conn = ConnectionHelper.OpenConnection())
            {
                return conn.Query<wuliu_account_ios_token>(sql, new { wuliu_id }).ToList();
            }
        }
        /// <summary>
        /// 通过物流ID获取Token
        /// </summary>
        /// <param name="wuliu_id"></param>
        /// <returns></returns>
        public List<wuliu_account_android_token> GetCompanyidAndroidToken(int company_id)
        {
            string sql = @"SELECT a.*,c.wuliu_id as wuliu_id from wuliu_account_android_token as a
                        LEFT JOIN wuliu_account_role as b on a.account_id=b.account_id
                        LEFT JOIN wuliu_account_wlcompany as c on a.account_id=c.account_id
                        LEFT JOIN wuliu_contract_base as d on d.wuliu_id =c.wuliu_id
                        WHERE b.role_id in (10,11) and d.company_id=@company_id and d.contract_flag=1 ";
            using (var conn = ConnectionHelper.OpenConnection())
            {
                return conn.Query<wuliu_account_android_token>(sql, new { company_id }).ToList();
            }
        }

        /// <summary>
        /// 通过物流ID获取Token
        /// </summary>
        /// <param name="wuliu_id"></param>
        /// <returns></returns>
        public List<wuliu_account_ios_token> GetCompanyidIOSToken(int company_id)
        {
            string sql = @"SELECT a.*,c.wuliu_id as wuliu_id from wuliu_account_ios_token as a
                        LEFT JOIN wuliu_account_role as b on a.account_id=b.account_id
                        LEFT JOIN wuliu_account_wlcompany as c on a.account_id=c.account_id
                        LEFT JOIN wuliu_contract_base as d on d.wuliu_id =c.wuliu_id
                        WHERE b.role_id in (10,11) and d.company_id=@company_id and d.contract_flag=1 ";
            using (var conn = ConnectionHelper.OpenConnection())
            {
                return conn.Query<wuliu_account_ios_token>(sql, new { company_id }).ToList();
            }
        }

       
    }
}
